﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Hxsoft.AppV1.Module;

namespace Hxsoft.AppV1.Admin.SiteManage.Controls
{
	public partial class Site : BaseUserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			this.DataBind();
		}


		/// <summary>
		/// 属性 SiteName
		/// </summary>
		public string SiteName
		{
			get
			{
				return Convert.ToString(CtrlSiteName.Text);
			}
			set
			{
				CtrlSiteName.Text = value.ToString();
			}
		}

		/// <summary>
		/// 属性 AreaCode
		/// </summary>
		public int? AreaCode
		{
			get
			{
				if (String.IsNullOrEmpty(CtrlAreaCode.Text))
					return null;

				return Convert.ToInt32(CtrlAreaCode.Text);
			}
			set
			{
				if (value == null)
					CtrlAreaCode.Text = "";
				else
					CtrlAreaCode.Text = value.ToString();
			}
		}

		/// <summary>
		/// 属性 Domain
		/// </summary>
		public string Domain
		{
			get
			{
				string strDomain = CtrlDomain.Text.Trim();
				if (String.IsNullOrEmpty(strDomain))
					return null;

				strDomain = strDomain.Pack(Sites.DomainSeparator);
				return strDomain;
			}
			set
			{
				if (value == null)
					CtrlDomain.Text = "";
				else
					CtrlDomain.Text = value.Unpack(Sites.DomainSeparator);
			}
		}

		/// <summary>
		/// 属性 Memo
		/// </summary>
		public string Memo
		{
			get
			{
				if (String.IsNullOrEmpty(CtrlMemo.Text))
					return null;

				return Convert.ToString(CtrlMemo.Text);
			}
			set
			{
				if (value == null)
					CtrlMemo.Text = "";
				else
					CtrlMemo.Text = value.ToString();
			}
		}


		/// <summary>
		/// 控件的 SiteInfo 实例。
		/// </summary>
		public Hxsoft.AppV1.Module.Site Info
		{
			get
			{
				Hxsoft.AppV1.Module.Site site = new Hxsoft.AppV1.Module.Site();

				site.SiteName = SiteName;
				site.AreaCode = AreaCode;
				site.Domain = Domain;
				site.Memo = Memo;

				return site;
			}
			set
			{
				if (value == null) return;

				SiteName = value.SiteName;
				AreaCode = value.AreaCode;
				Domain = value.Domain;
				Memo = value.Memo;
			}
		}
	}
}